package com.xinxin.blockchain.util;

import com.github.pagehelper.Page;

import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author ys
 * @date 2020/5/21
 */
public class PageBeanUtil {

    private PageBeanUtil() {
    }

    /**
     * 转换分页结果对象
     */
    public static <T> Page<T> convertPageObject(Page<?> pageList, Function<Object, T> converter) {
        Page<T> page = new Page<>(pageList.getPageNum(), pageList.getPageSize());
        page.setPages(pageList.getPages());
        page.setTotal(pageList.getTotal());
        page.addAll(pageList.stream().map(converter).collect(Collectors.toList()));
        return page;
    }
}
